<!--留言的展示-->
<br>
<% post.comments.forEach(function (comment) { %>
<p>
    <%= comment.name %>
    <span class="info"> 回复于 <%= comment.time %></span>
</p>
<p><%- comment.content %></p>
<% }) %>

<!--添加留言的表单-->
<% if (user) { %>
<form method="post" action="/comment/<%= post.name %>/<%= post.time.second %>/<%= post.title %>">
    发布人:<%= user.name %>
    <input type="hidden" name="name" value="<%= user.name %>"/><br/>
    <textarea name="content" rows="5" cols="80"></textarea><br/>
    <input type="submit" value="留言" class="btn"/>
</form>

<% }else { %>
<form method="post">
    回应请先 <a href="/login">登录</a>或<a href="/reg">注册</a><br>
    <textarea name="" id="" cols="30" rows="10" id="tb"></textarea><br>
    <input type="submit" value="留言" class="btn" id="sb"/>
</form>
<% } %>
<script>
    window.onload = function () {
        var textarea = document.querySelector('#tb')
        var button = document.querySelector('#sb')
        button.onclick = function (e) {
            e.preventDefault();
            location.href = '/login'
        }
        textarea.onfocus = function () {
            location.href = '/login'
        }
    }
</script>